﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
using System.Windows.Forms;

namespace UrlParamFormat
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void btnFormat_Click(object sender, EventArgs e)
        {
            try
            {
                string str = this.txtURL.Text.Trim();
                NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(str, Encoding.UTF8);
                List<string> strs = new List<string>();
                string[] allKeys = nameValueCollection.AllKeys;
                for (int i = 0; i < (int)allKeys.Length; i++)
                {
                    var value = allKeys[i];
                    string item = HttpUtility.UrlDecode(nameValueCollection[value], Encoding.UTF8);
                    strs.Add(string.Concat(value, "=", item));
                }
                this.txtContent.Text = string.Join("\r\n\r\n", strs);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
